package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;

/**
 * H_WebService_IPTV_Imp_getHwIptvPpvOrder 华为IPTV接口-查询用户所有按次订购关系
 * 
 * @author xuzhi
 * 
 */
public class H_WebService_IPTV_Imp_getHwIptvPpvOrder implements WorkInterFace {

	@Override
	public String getName() {
		return "华为IPTV接口-查询用户所有按次订购关系";
	}

	@Override
	public String getDesciption() {
		return null;
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in = new Attr[1];
		in[0] = new Attr("UserID", "IPTV用户帐号，参数只包含数字、字母、下划线、点和 '@'符号",
				AttrType.TYPE_String, true);
//		in[1] = new Attr("SequenceID",
//				"操作流水号，唯一识别.可使用yyymmddhh24miss+3位数字序列号的生成规则",
//				AttrType.TYPE_String, true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[10];
		out[0] = new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1] = new Attr("ReturnMessage", "失败时返回错误信息", AttrType.TYPE_String,
				true);
		out[2] = new Attr("PpvOrderInfo", "包月订购信息", AttrType.TYPE_String, true);
		out[3] = new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String,
				true);
		out[4] = new Attr("ProductId", "产品ID", AttrType.TYPE_String, false);
		out[5] = new Attr("ContentId", "内容ID", AttrType.TYPE_String, false);
		out[6] = new Attr("StartTime", "订购开始时间,格式：yyyymmddhh24miss",
				AttrType.TYPE_String, false);
		out[7] = new Attr("EndTime", "订购结束时间,格式：yyyymmddhh24miss",
				AttrType.TYPE_String, false);
		out[8] = new Attr("CreateTime", "订购时间,格式：yyyymmddhh24miss",
				AttrType.TYPE_String, false);
		out[9] = new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取",
				AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn = new AttrsIn();
		WebService webService = new WebService();
		Map<String, Object> map = new HashMap<String, Object>();
		// Get into arguments
		attrsIn.setClientSysName("10000号");
		attrsIn.setFunctionName("getHwIptvPpvOrder");
		attrsIn.setRequestMessage("<UserID>"+(String) data.get("UserID")+"</UserID><SequenceID>"+webService.getrandom()+"</SequenceID>");
		// Get soapxml
		String returnXml = webService.WebServiceInit(attrsIn);
		String flag = webService.getPattern("flag", returnXml);
		if (flag.equals("true")) {
			map.put("ReturnCode", Integer.parseInt(webService.getPattern(
					"ReturnCode", returnXml)));
			map.put("ReturnMessage",
					webService.getPattern("ReturnMessage", returnXml));
			map.put("PpvOrderInfo",
					webService.getPattern("PpvOrderInfo", returnXml));
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("ReturnMessage", "");
			map.put("PpvOrderInfo", "");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		return map;
	}

}
